package com.boonya.rmi.order.config;

import com.boonya.rmi.order.service.IOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

/**
 * @ClassName: RmiConfig
 * @Description: TODO(RMI服务绑定)
 * @author: pengjunlin
 * @motto: 学习需要毅力，那就秀毅力
 * @date 2021/4/21 16:38
 */
@Configuration
public class RmiConfig {

    @Autowired
    IOrder order;

    @PostConstruct
    public void init() {
        try {
            LocateRegistry.createRegistry(1099);
            //IOrder order = new OrderManager();
            Naming.rebind("orderService", order);
            System.out.println("=========发布RMI orderService服务==========");
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
}
